//
//  ActionElementViewController.m
//  PacIsBack
//
//  Created by Simon André on 13/02/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ActionElementViewController.h"
#import "AbilityProtocol.h"
#import "ActionsListViewController.h"
#import "Constants.h"


@implementation ActionElementViewController
@synthesize actionsList, ability, label;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

-(id) initWithAction:(id<AbilityProtocol>) abilityForElement andList:(ActionsListViewController*) mainList{
	if (self = [super init]) {
		[self setAbility:abilityForElement];
		[self setActionsList:mainList];
		
		UIFont* font = [UIFont fontWithName:@"MarkerFelt-Thin" size:17.0];
		NSString* text = [[self ability] shownName];
		if ([[self ability] mpCost]>0) {
			text = [NSString stringWithFormat:@"%@%@%D%@",text,@"(",[[self ability] mpCost],@")"];
		}
		CGFloat textActionHeight = [text sizeWithFont:font].height;
		UIView* emptyView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, actionListWidth, textActionHeight)];
		[self setView:emptyView];
		[emptyView release];
		UILabel* actionNameView = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, actionListWidth, textActionHeight)];
		[actionNameView setText:text];
		[actionNameView setBackgroundColor:[UIColor clearColor]];
		[actionNameView setTextAlignment:UITextAlignmentLeft];
		[actionNameView setFont:font];
		[actionNameView setUserInteractionEnabled:YES];
		[[self view] addSubview:actionNameView];
		[self setLabel:actionNameView];
		[actionNameView release];
	}
	return self;
}

-(void) select{
	[[self label] setBackgroundColor:[UIColor purpleColor]];
	[[self actionsList] selectAbility:self];
	[[self view] setUserInteractionEnabled:YES];
}

-(void) unselect{
	[[self label] setBackgroundColor:[UIColor clearColor]];
	[[self view] setUserInteractionEnabled:YES];
}

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	[self select];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[self setActionsList:nil];
	[self setAbility:nil];
	[self setLabel:nil];
	[super dealloc];
}


@end
